package org.example.controller;

import org.example.model.Classes;
import org.example.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/classes")
public class ClassesController {
    @Autowired
    private ClassesService classesService;

    //获取班级信息（下拉菜单获取班级选项）
    //GET /api/classes/queryAsDict
    @RequestMapping("/queryAsDict")
    public Object queryAsDict(){
        List<Classes> classes = classesService.queryAsDict();
        return classes;
    }

    //获取班级信息（表格展示）
    //GET /api/classes/query
    @RequestMapping("/query")
    public Object query(){
        List<Classes> classes = classesService.query();
        return classes;
    }

    //新增班级
    //POST /api/classes/add
    //{"classesName":"测试","classesGraduateYear":"000001002","classesMajor":"000002001","classesDesc":""}
    @RequestMapping("/add")
    public Object add(@RequestBody Classes classes){
        int n = classesService.add(classes);
        return null;
    }

    //获取班级详情（修改班级时，先查询）
    //GET /api/classes/queryById?id=xxx
    @RequestMapping("/queryById")
    public Object queryById(Integer id){
        Classes classes = classesService.queryById(id);
        return classes;
    }

    //修改班级信息（根据主键修改其他非主键字段）
    //POST /api/classes/update
    //{"id":"4","classesName":"测试222","classesGraduateYear":"000001003","classesMajor":"000002002","classesDesc":""}
    @RequestMapping("/update")
    public Object update(@RequestBody Classes classes){
        int n = classesService.update(classes);
        return null;
    }

    //删除班级（一个或多个）
    //GET /api/classes/delete?ids=xxx&ids=xxx
    @RequestMapping("/delete")
    public Object delete(@RequestParam List<Integer> ids){
        int n = classesService.delete(ids);
        return null;
    }
}
